package org.jsola.hr.constant;

import org.jsola.core.validator.IConst;
import org.jsola.json.JsonKit;

import java.util.HashMap;
import java.util.Map;

/**
 * 社保缴费类型
 *
 * @author zhr
 */
public enum SocPayCostType implements IConst {

    /**
     * 正常应缴
     */
    NORMAL_PAY_COST(1,"正常应缴"),
    /**
     * 调整计划
     */
    FILL_DIFFERENCE(2,"调整计划"),
    /**
     * 补收/补缴
     */
    FILL_COLLECT(3,"补收/补缴"),
    /**
     * 个人退收
     */
    REFUND_CHARGE(4,"个人退收"),
    /**
     * 补收
     */
    FILL_GATHER(5,"补收"),
    /**
     * 补缴
     */
    FILL_PAYMENT(6,"补缴"),
    /**
     * 社保退费
     */
    REFUNDS(7,"社保退费");

    private final Integer value;
    private final String desc;
    /**
     * 枚举值罗列，给swagger接口文档展示用
     */
    public static final String VALUES_STR = "1,2,3,4,5,6,7";

     /**
     * 缓存所有value
     */
    private static final Map<Integer, SocPayCostType> LOOKUP = new HashMap<>();

    static {
        for (SocPayCostType e : SocPayCostType.values()) {
            LOOKUP.put(e.value, e);
        }
    }


    SocPayCostType(Integer value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    /**
     * 根据value查找SocPayCostType
     * @param value value
     * @return SocPayCostType
     */
    public static SocPayCostType find(Integer value) {
        return LOOKUP.get(value);
    }

    /**
     * 根据desc查找SocPayCostType
     * @param desc desc
     * @return SocPayCostType
     */
    public static SocPayCostType findByDesc(String desc){
        for (SocPayCostType e : SocPayCostType.values()) {
            if(e.getDesc().equals(desc)){
                return e;
            }
        }
        return null;
    }

    /**
     * 所有枚举转json
     * @return json
     */
    public static String getAllToJson() {
        Map<String,Object> map = new HashMap<>();
        for (SocPayCostType e : SocPayCostType.values()) {
            map.put("value", e.value);
            map.put("desc", e.desc);
        }
        return JsonKit.toJSONString(map);
    }

    @Override
    public boolean check(Object obj) {
        Integer value = (Integer) obj;
        return find(value) != null;
    }

    public Integer getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }
}
